#ifndef LIGHT_EMITTING_MATERIAL_H
#define LIGHT_EMITTING_MATERIAL_H
#include "configurable.h"
#include "material.h"
#include "light_source.h"
namespace gemren
{
	class light_emitting_material : public bsdf_material, light_source
	{
	public:
		//virtual void interact(random* ran, const scene* sc, intersection* i);
		//virtual void interact_fast(random* ran, const scene* sc, intersection* i);
		
		light_emitting_material (): bsdf_material(){}
		virtual void direct_lighting(random* ran, const scene* sc, intersection* i);
		template<typename Cont>
		void add_emitting_triangles(const Cont& tris)
		{
			//embree::Lock<embree::MutexSys> lock(mutex);
			my_triangles.insert(my_triangles.end(), tris.begin(), tris.end());
		}
		void add_emitting_triangle(const size_t tri)
		{
			//embree::Lock<embree::MutexSys> lock(mutex);
			my_triangles.push_back(tri);
		}

		size_t get_triangle(random& r)
		{
			return my_triangles[r.get()%my_triangles.size()];
		}
		virtual void enlighten_spot(const scene* sc, random* ran, intersection* i, float factor);
		virtual err_t set_string(std::string& name, const std::string& value);
		virtual void announce_properties(const std::string& prefix, property_announcer announcer);
		const color_s& get_intensity() const { return color; }
		virtual bool is_light_emitting(){return true;}
	protected:
		
		std::vector<size_t> my_triangles;
		embree::MutexSys mutex;
	};
}

#endif